package com.bsoft.gol.editor.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import ctd.controller.exception.ControllerException;
import hcn.util.BaseResponse;
import com.bsoft.gol.editor.editor.EditorQuestionnaireTitle;
import com.bsoft.gol.editor.editor.EditorTitleOption;
import com.bsoft.gol.editor.editor.request.CollectTitleRequest;
import com.bsoft.gol.editor.editor.request.GetQuestionnaireDetailRequest;
import com.bsoft.gol.editor.editor.request.QueryCollectionListRequest;
import com.bsoft.gol.editor.editor.response.EditorQuestionnaireDetailRes;
import com.bsoft.gol.editor.editor.response.QueryCollectionListResponse;
import com.bsoft.gol.editor.editor.response.QueryEditorOptionListResponse;
import com.bsoft.gol.editor.editor.response.QueryEditorTitleListResponse;
import hcn.util.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bsoft.gol.editor.service.EditorQuestionnaireTitleApi;
import com.bsoft.gol.editor.utils.CommonUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

//import com.bsoft.gol.editor.utils.CommonUtils;
//import com.com.bsoft.gol.editor.editor.entity.BaseResponse;
//import com.com.bsoft.gol.editor.editor.hessian.com.bsoft.gol.editor.editor.EditorQuestionnaireTitleApi;
//import com.com.bsoft.gol.editor.editor.com.bsoft.gol.editor.model.EditorQuestionnaireTitle;
//import com.com.bsoft.gol.editor.editor.com.bsoft.gol.editor.model.EditorTitleOption;
//import com.com.bsoft.gol.editor.editor.com.bsoft.gol.editor.model.com.bsoft.gol.editor.editor.request.EditorQuestionnaireTitleReq;
//import com.com.bsoft.gol.editor.editor.com.bsoft.gol.editor.model.com.bsoft.gol.editor.editor.response.EditorQuestionnaireDetailRes;
//import com.com.bsoft.gol.editor.editor.com.bsoft.gol.editor.model.request.GetQuestionnaireDetailRequest;

/**
 *
 * @author zhangjie
 * @date 2019/6/19
 */
@RestController
@RequestMapping(value = "/api/auth/editorQuestionnaireTitle")
public class EditorQuestionnaireTitleController extends ApiBaseController{
    private static final Logger LOGGER = LoggerFactory.getLogger(EditorQuestionnaireTitleController.class);

    @Autowired
    private EditorQuestionnaireTitleApi editorQuestionnaireTitleApi;

    /**
     * 新增题目信息 包括题号的修改
     *
     * @param editorQuestionnaireTitleReq
     * @return
     */
    @RequestMapping("/add")
    public BaseResponse<EditorQuestionnaireTitle> add(@RequestBody EditorQuestionnaireTitle editorQuestionnaireTitleReq, HttpServletRequest request) {
        BaseResponse<EditorQuestionnaireTitle> response = new BaseResponse<EditorQuestionnaireTitle>();
        EditorQuestionnaireTitle editorQuestionnaireTitle = null;
        //titleId为空  表示新增题目
        if(CommonUtils.isNull(editorQuestionnaireTitleReq.getTitleId())){
            if (CommonUtils.isNull(editorQuestionnaireTitleReq.getWidgetType()) || CommonUtils.isNull(editorQuestionnaireTitleReq.getQuestionnaireId())
                    || CommonUtils.isNull(editorQuestionnaireTitleReq.getTitleName())
                    || CommonUtils.isEmpty(editorQuestionnaireTitleReq.getTitleNum())
                    || CommonUtils.isEmpty(editorQuestionnaireTitleReq.getOrderNum())) {
                response.setCode(ResultCode.PARAMETERS_EMPTY);
                response.setMessage("传入参数不能为空");
                return response;
            }
            if(editorQuestionnaireTitleReq.getTitleNum()<0
                    || editorQuestionnaireTitleReq.getOrderNum()<=0||editorQuestionnaireTitleReq.getOrderNum()<editorQuestionnaireTitleReq.getTitleNum()){
                response.setCode(ResultCode.PARAMETERS_NOTLEGAL);
                response.setMessage("传入参数错误");
                return response;
            }
        }else{//titleId不为空  表示新增题库题目
             // 题库题目
            if (CommonUtils.isNull(editorQuestionnaireTitleReq.getQuestionnaireId())
                    || CommonUtils.isNull(editorQuestionnaireTitleReq.getTitleId())
                    || CommonUtils.isEmpty(editorQuestionnaireTitleReq.getTitleNum())
                    || CommonUtils.isEmpty(editorQuestionnaireTitleReq.getOrderNum())) {
                response.setCode(ResultCode.PARAMETERS_EMPTY);
                response.setMessage("传入参数不能为空");
                return response;
            }
            if(editorQuestionnaireTitleReq.getTitleNum()<0
                    || editorQuestionnaireTitleReq.getOrderNum()<=0||editorQuestionnaireTitleReq.getOrderNum()<editorQuestionnaireTitleReq.getTitleNum()){
                response.setCode(ResultCode.PARAMETERS_NOTLEGAL);
                response.setMessage("传入参数错误");
                return response;
            }
        }


        try {
            editorQuestionnaireTitle = editorQuestionnaireTitleApi.add(editorQuestionnaireTitleReq);
        } catch (ControllerException e) {
            e.printStackTrace();
            response.setCode(ResultCode.ERROR);
            response.setMessage(e.getMessage());
            return response;
        }

        response.setData(editorQuestionnaireTitle);
        response.setMessage("保存成功");
        return response;
    }


    /**
     * 修改题目信息
     *
     * @param editorQuestionnaireTitleReq
     * @return
     */
    @RequestMapping(value = "update")
    public BaseResponse<EditorQuestionnaireTitle> update(@RequestBody EditorQuestionnaireTitle editorQuestionnaireTitleReq, HttpServletRequest request) {
        BaseResponse<EditorQuestionnaireTitle> response = new BaseResponse<EditorQuestionnaireTitle>();
        if (CommonUtils.isNull(editorQuestionnaireTitleReq.getTitleId())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }

        editorQuestionnaireTitleApi.update(editorQuestionnaireTitleReq);
        response.setMessage("修改成功");
        return response;
    }

    /**
     * 删除题目信息 包括题目关联表数据
     *
     * @param editorQuestionnaireTitleReq
     * @return
     */
    @RequestMapping(value = "delete")
    public BaseResponse<EditorQuestionnaireTitle> delete(@RequestBody EditorQuestionnaireTitle editorQuestionnaireTitleReq, HttpServletRequest request) {
        BaseResponse<EditorQuestionnaireTitle> response = new BaseResponse<EditorQuestionnaireTitle>();
        if (CommonUtils.isNull(editorQuestionnaireTitleReq.getTitleId())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        editorQuestionnaireTitleApi.delete(editorQuestionnaireTitleReq);
        response.setMessage("删除成功");
        return response;
    }
//
    /**
     * 复制题目信息 包括题目关联表数据
     *
     * @param editorQuestionnaireTitleReq
     * @return
     */
    @RequestMapping(value = "copyTitle")
    public BaseResponse<EditorQuestionnaireTitle> copyTitle(@RequestBody EditorQuestionnaireTitle editorQuestionnaireTitleReq, HttpServletRequest request) {
        BaseResponse<EditorQuestionnaireTitle> response = new BaseResponse<EditorQuestionnaireTitle>();
        if (CommonUtils.isNull(editorQuestionnaireTitleReq.getTitleId())
                || CommonUtils.isEmpty(editorQuestionnaireTitleReq.getTitleNum())
                || CommonUtils.isEmpty(editorQuestionnaireTitleReq.getOrderNum())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        if(editorQuestionnaireTitleReq.getTitleNum()<0
                || editorQuestionnaireTitleReq.getOrderNum()<=0||editorQuestionnaireTitleReq.getOrderNum()<editorQuestionnaireTitleReq.getTitleNum()){
            response.setCode(ResultCode.PARAMETERS_NOTLEGAL);
            response.setMessage("传入参数错误");
            return response;
        }

        EditorQuestionnaireTitle editorQuestionnaireTitle = editorQuestionnaireTitleApi.copyTitle(editorQuestionnaireTitleReq);
        response.setData(editorQuestionnaireTitle);
        response.setMessage("操作成功");
        return response;
    }

    /**
     * 修改题号
     *
     * @param editorQuestionnaireTitleReq
     * @return
     */
    @RequestMapping(value = "updateTitleNum")
    public BaseResponse<EditorQuestionnaireTitle> updateTitleNum(@RequestBody EditorQuestionnaireTitle editorQuestionnaireTitleReq, HttpServletRequest request) {
        BaseResponse<EditorQuestionnaireTitle> response = new BaseResponse<EditorQuestionnaireTitle>();
        if (CommonUtils.isEmpty(editorQuestionnaireTitleReq.getPreTitleNum())
                || CommonUtils.isEmpty(editorQuestionnaireTitleReq.getAfterTitleNum())
                ||CommonUtils.isNull(editorQuestionnaireTitleReq.getTitleId())
                ||CommonUtils.isNull(editorQuestionnaireTitleReq.getQuestionnaireId())
                || CommonUtils.isEmpty(editorQuestionnaireTitleReq.getPreOrderNum())
                || CommonUtils.isEmpty(editorQuestionnaireTitleReq.getAfterOrderNum())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        //排序号要大于0
        if (editorQuestionnaireTitleReq.getPreOrderNum()<=0
                || editorQuestionnaireTitleReq.getAfterOrderNum()<=0
                || editorQuestionnaireTitleReq.getPreTitleNum()<0
                || editorQuestionnaireTitleReq.getAfterTitleNum()<0
                ) {
            response.setCode(ResultCode.PARAMETERS_NOTLEGAL);
            response.setMessage("传入参数错误");
            return response;
        }
        editorQuestionnaireTitleApi.updateTitleNum(editorQuestionnaireTitleReq);
        response.setMessage("修改成功");
        return response;
    }

    /**
     * 新增题目选项
     *
     * @param editorTitleOptionReq
     * @return
     */
    @RequestMapping("/addOption")
    public BaseResponse<EditorTitleOption> addOption(@RequestBody EditorTitleOption editorTitleOptionReq, HttpServletRequest request) {
        BaseResponse<EditorTitleOption> response = new BaseResponse<EditorTitleOption>();
        EditorTitleOption editorTitleOption = null;
        //控件类型 1单选题、2多选题、7多项填空、9表格矩阵、21，22检查检验矩阵
        if (CommonUtils.isNull(editorTitleOptionReq.getTitleId())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        String optionIds = "";
        EditorQuestionnaireTitle editorQuestionnaireTitle = editorQuestionnaireTitleApi.selectTitleByPrimaryKey(editorTitleOptionReq.getTitleId());
        if(editorQuestionnaireTitle.getWidgetType()==1||
                editorQuestionnaireTitle.getWidgetType()==2 ||
                editorQuestionnaireTitle.getWidgetType()==3||
                editorQuestionnaireTitle.getWidgetType()==7||
                editorQuestionnaireTitle.getWidgetType()==14||
                //联系电话
                editorQuestionnaireTitle.getWidgetType()==15||
                //婚姻状况
                editorQuestionnaireTitle.getWidgetType()==26||
                //身高
                editorQuestionnaireTitle.getWidgetType()==27||
                //体重
                editorQuestionnaireTitle.getWidgetType()==28||
                //文化程度
                editorQuestionnaireTitle.getWidgetType()==29||
                //医保方式
                editorQuestionnaireTitle.getWidgetType()==30||
                //联系人
                editorQuestionnaireTitle.getWidgetType()==31||
                //联系人电话
                editorQuestionnaireTitle.getWidgetType()==32||
                //居住地址
                editorQuestionnaireTitle.getWidgetType()==33
            ){
            if (CommonUtils.isNull(editorTitleOptionReq.getOptionContent())||CommonUtils.isNull(editorTitleOptionReq.getOptionNums())) {
                response.setCode(ResultCode.PARAMETERS_EMPTY);
                response.setMessage("传入参数不能为空");
                return response;
            }
            //OptionContent有多个
            String lineSeparator = System.getProperty("line.separator", "\n");
            List<String> optionContents = Arrays.asList(editorTitleOptionReq.getOptionContent().split(lineSeparator));
            String [] arr = editorTitleOptionReq.getOptionNums().split(",");
            List<String> optionNums = Arrays.asList(arr);
            if(optionContents.size()!=optionNums.size()){
                response.setCode(ResultCode.PARAMETERS_NOTLEGAL);
                response.setMessage("传入参数错误");
                return response;
            }
            for(int i =0;i<optionContents.size();i++){
                editorTitleOptionReq.setOptionNum(Integer.parseInt(arr[i]));//选项号
                editorTitleOptionReq.setOptionContent(optionContents.get(i));//选项内容
                editorTitleOptionReq.setOptionId(UUID.randomUUID().toString().replaceAll("-", ""));
                editorTitleOption = editorQuestionnaireTitleApi.addOption(editorTitleOptionReq);
                optionIds+=editorTitleOption.getOptionId()+",";
            }
            if(!"".equals(optionIds)){
                optionIds = optionIds.substring(0,optionIds.length()-1);
            }
        }else if(editorQuestionnaireTitle.getWidgetType()==5){//级联选
            if (CommonUtils.isNull(editorTitleOptionReq.getOptionContent())) {
                response.setCode(ResultCode.PARAMETERS_EMPTY);
                response.setMessage("传入参数不能为空");
                return response;
            }
            //级联选操作
            JSONArray items = JSONObject.parseArray(editorTitleOptionReq.getOptionContent());
            JSONObject row = null;
            for(int i=0; i<items.size(); i++) {
                row = items.getJSONObject(i);
                editorTitleOptionReq.setOptionId(UUID.randomUUID().toString().replaceAll("-", ""));
                editorTitleOptionReq.setOptionContent(row.get("name").toString());
                editorTitleOptionReq.setPid("0");
                EditorTitleOption editorTitleOption1 = editorQuestionnaireTitleApi.addOption(editorTitleOptionReq);
                String optionId1=editorTitleOption1.getOptionId();

                if (row.get("options") != null) {
                    JSONArray options = JSONObject.parseArray(row.get("options").toString());
                    if (options.size() >= 1) {
                        for (int j = 0; j < options.size(); j++) {
                            JSONObject row1 = options.getJSONObject(j);
                            editorTitleOptionReq.setPid(optionId1);
                            editorTitleOptionReq.setOptionContent(row1.get("name").toString());
                            editorTitleOptionReq.setOptionId(UUID.randomUUID().toString().replaceAll("-", ""));
                            EditorTitleOption editorTitleOption2 = editorQuestionnaireTitleApi.addOption(editorTitleOptionReq);
                            String optionId2=editorTitleOption2.getOptionId();
                            if (row1.get("options") != null) {
                                JSONArray options1 = JSONObject.parseArray(row1.get("options").toString());
                                if (options1.size() >= 1) {
                                    for (int k = 0; k < options1.size(); k++) {
                                        JSONObject row2 = options1.getJSONObject(k);
                                        editorTitleOptionReq.setPid(optionId2);
                                        editorTitleOptionReq.setOptionContent(row2.get("name").toString());
                                        editorTitleOptionReq.setOptionId(UUID.randomUUID().toString().replaceAll("-", ""));
                                        EditorTitleOption editorTitleOption3 = editorQuestionnaireTitleApi.addOption(editorTitleOptionReq);
                                        String optionId3=editorTitleOption3.getOptionId();

                                        if (row2.get("options") != null) {
                                            JSONArray options2 = JSONObject.parseArray(row2.get("options").toString());
                                            if (options2.size() >= 1) {
                                                for (int m = 0; m < options2.size(); m++) {
                                                    JSONObject row3 = options2.getJSONObject(m);
                                                    editorTitleOptionReq.setOptionContent(row3.get("name").toString());
                                                    editorTitleOptionReq.setPid(optionId3);
                                                    editorTitleOptionReq.setOptionId(UUID.randomUUID().toString().replaceAll("-", ""));
                                                    EditorTitleOption editorTitleOption4 = editorQuestionnaireTitleApi.addOption(editorTitleOptionReq);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                optionIds =editorTitleOption1.getOptionId();
            }
            optionIds += optionIds;
        }else if(editorQuestionnaireTitle.getWidgetType()==9||
                //检验记录
                editorQuestionnaireTitle.getWidgetType()==21||
                //检查记录
                editorQuestionnaireTitle.getWidgetType()==22||
                //门诊情况
                editorQuestionnaireTitle.getWidgetType()==23||
                //住院情况
                editorQuestionnaireTitle.getWidgetType()==24||
                //病历记录
                editorQuestionnaireTitle.getWidgetType()==34||
                //手术操作
                editorQuestionnaireTitle.getWidgetType()==25||
                //病理记录
                editorQuestionnaireTitle.getWidgetType()==36||
                //评估评分
                editorQuestionnaireTitle.getWidgetType()==37||
                //用药记录
                editorQuestionnaireTitle.getWidgetType()==38||
                //门诊处置
                editorQuestionnaireTitle.getWidgetType()==39
                ){//矩阵
            if (CommonUtils.isNull(editorTitleOptionReq.getOptionContent())) {
                response.setCode(ResultCode.PARAMETERS_EMPTY);
                response.setMessage("传入参数不能为空");
                return response;
            }
            JSONArray items = JSONObject.parseArray(editorTitleOptionReq.getOptionContent());
            for(int i=0; i<items.size(); i++) {
                JSONObject row = items.getJSONObject(i);
                editorTitleOptionReq.setOptionId(UUID.randomUUID().toString().replaceAll("-", ""));
                editorTitleOptionReq.setOptionContent(row.get("content").toString());
                if(CommonUtils.isNotNull(row.get("optionExplain"))) {
                    editorTitleOptionReq.setOptionExplain(row.get("optionExplain").toString());
                }
                editorTitleOptionReq.setRowNum(Integer.parseInt(row.get("rowNum").toString()));
                editorTitleOptionReq.setColNum(Integer.parseInt(row.get("colNum").toString()));
                EditorTitleOption editorTitleOption1 = editorQuestionnaireTitleApi.addOption(editorTitleOptionReq);
                optionIds =editorTitleOption1.getOptionId();
            }
            optionIds += optionIds;
        }else{
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("题目类型错误");
            return response;
        }

        //editorTitleOption.setOptionIds(optionIds);
        response.setData(editorTitleOption);
        response.setMessage("保存成功");
        return response;
    }
//
    /**
     * 修改题目选项
     *
     * @param editorTitleOptionReq
     * @return
     */
    @RequestMapping(value = "updateOption")
    public BaseResponse<EditorTitleOption> updateOption(@RequestBody EditorTitleOption editorTitleOptionReq, HttpServletRequest request) {
        BaseResponse<EditorTitleOption> response = new BaseResponse<EditorTitleOption>();
        if (CommonUtils.isNull(editorTitleOptionReq.getTitleId())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        EditorQuestionnaireTitle editorQuestionnaireTitle = editorQuestionnaireTitleApi.selectTitleByPrimaryKey(editorTitleOptionReq.getTitleId());
        if(editorQuestionnaireTitle.getWidgetType()==5){
            if (CommonUtils.isNull(editorTitleOptionReq.getPid())) {
                response.setCode(ResultCode.PARAMETERS_EMPTY);
                response.setMessage("传入参数不能为空");
                return response;
            }
        }else{
            if (CommonUtils.isNull(editorTitleOptionReq.getOptionId())) {
                response.setCode(ResultCode.PARAMETERS_EMPTY);
                response.setMessage("传入参数不能为空");
                return response;
            }
        }
        if(CommonUtils.isNull(editorTitleOptionReq.getOptionId())){
            editorTitleOptionReq.setOptionId(UUID.randomUUID().toString().replaceAll("-", ""));
            editorQuestionnaireTitleApi.addOption(editorTitleOptionReq);
        }else{
            editorQuestionnaireTitleApi.updateOption(editorTitleOptionReq);
        }

        response.setMessage("修改成功");
        return response;
    }
//
    /**
     * 删除题目选项 包括题目关联表数据
     *
     * @param editorTitleOptionReq
     * @return
     */
    @RequestMapping(value = "deleteOption")
    public BaseResponse<EditorTitleOption> deleteOption(@RequestBody EditorTitleOption editorTitleOptionReq, HttpServletRequest request) {
        BaseResponse<EditorTitleOption> response = new BaseResponse<EditorTitleOption>();
        if (CommonUtils.isNull(editorTitleOptionReq.getOptionIds())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        editorQuestionnaireTitleApi.deleteOption(editorTitleOptionReq);
        response.setMessage("删除成功");
        return response;
    }
//
    /**
     * 修改选项号
     * @param editorTitleOptionReq
     * @return
     */
    @RequestMapping(value = "updateOptionNum")
    public BaseResponse<EditorTitleOption> updateOptionNum(@RequestBody EditorTitleOption editorTitleOptionReq, HttpServletRequest request) {
        BaseResponse<EditorTitleOption> response = new BaseResponse<EditorTitleOption>();
        if (CommonUtils.isNull(editorTitleOptionReq.getOptionIds())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        List<String> optionIds = Arrays.asList(editorTitleOptionReq.getOptionIds().split(","));
        for(int i =1;i<=optionIds.size();i++){
            editorTitleOptionReq.setOptionId(optionIds.get(i-1));
            editorTitleOptionReq.setOptionNum(i);
            editorQuestionnaireTitleApi.updateOption(editorTitleOptionReq);
        }
        response.setMessage("修改成功");
        return response;
    }
//
    /**
     * 获取表单详情
     * @param getQuestionnaireDetailRequest
     * @return
     */
    @RequestMapping("/getQuestionnaireDetail")
    public BaseResponse<EditorQuestionnaireDetailRes> getQuestionnaireDetail(@RequestBody GetQuestionnaireDetailRequest getQuestionnaireDetailRequest, HttpServletRequest request) {
        BaseResponse<EditorQuestionnaireDetailRes> response = new BaseResponse<EditorQuestionnaireDetailRes>();
//        Long uid  = getUid(request);
//        if(CommonUtils.isNull(getQuestionnaireDetailRequest.getUid())){
//            response.setCode(ResultCode.PARAMETERS_EMPTY);
//            response.setMessage("传入参数不能为空");
//            return response;
//        }
        //editorQuestionnaireStyle.setUid(uid);

        if (CommonUtils.isNull(getQuestionnaireDetailRequest.getQuestionnaireId())
                || CommonUtils.isNull(getQuestionnaireDetailRequest.getDeviceType())
                || CommonUtils.isNull(getQuestionnaireDetailRequest.getShowType())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }

        EditorQuestionnaireDetailRes editorQuestionnaireDetailRes =
                editorQuestionnaireTitleApi.getQuestionnaireDetail(getQuestionnaireDetailRequest);
        response.setData(editorQuestionnaireDetailRes);
        if(editorQuestionnaireDetailRes==null){
            response.setMessage("请检查表单id是否存在");
            response.setCode(500);
        }
        if(CommonUtils.isNotEmpty(editorQuestionnaireDetailRes.getQuestionnaireState())&&editorQuestionnaireDetailRes.getQuestionnaireState().equals((byte)3)&&getQuestionnaireDetailRequest.getShowType()!=(byte)2){
            response.setData(null);
            response.setMessage("该问卷已被关闭，无法填写");
            response.setCode(500);
        }
        return response;
    }

    /**
     * 题目列表
     * @param req
     * @return
     */
    @RequestMapping("/titleList")
    public BaseResponse<QueryEditorTitleListResponse> list(@RequestBody EditorQuestionnaireTitle req) {

        BaseResponse<QueryEditorTitleListResponse> baseResponse = editorQuestionnaireTitleApi.queryQuestionnaireTitleList(req);


        return baseResponse;
    }


    /**
     * 题目选项列表
     * @param req
     * @return
     */
    @RequestMapping("/optionList")
    public BaseResponse<QueryEditorOptionListResponse> list(@RequestBody EditorTitleOption req) {

        BaseResponse<QueryEditorOptionListResponse> baseResponse = editorQuestionnaireTitleApi.queryQuestionnaireOptionList(req);


        return baseResponse;
    }

    /**
     * @description: 查询问卷题目收藏列表
     * @author: chenJij@bsoft.com.cn
     * @date: 2021/10/11 14:27
     * @param: req
     * @return: com.bsoft.gol.editor.editor.BaseResponse<java.util.List<com.bsoft.gol.editor.editor.response.QueryCollectionListResponse>>
     */
    @RequestMapping("/queryCollectionList")
    public BaseResponse<List<QueryCollectionListResponse>> queryCollectionList(@RequestBody QueryCollectionListRequest req) {
        BaseResponse<List<QueryCollectionListResponse>> baseResponse = new BaseResponse<>();
        try {
            List<QueryCollectionListResponse> queryQuestionnaireOptionList = editorQuestionnaireTitleApi.queryCollectionList(req);
            baseResponse.setData(queryQuestionnaireOptionList);
        }catch (Exception e){

            baseResponse.setCode(ResultCode.ERROR);
            baseResponse.setMessage("查询收藏记录列表失败");
        }
        return baseResponse;
    }


    /**
     * @description: 收藏问卷题目
     * @author: chenJij@bsoft.com.cn
     * @date: 2021/10/11 14:54
     * @param: req
     * @return: com.bsoft.gol.editor.editor.BaseResponse
     */
    @RequestMapping("/collect")
    public BaseResponse collect(@RequestBody CollectTitleRequest req) {
        BaseResponse baseResponse = new BaseResponse<>();
        try {
            editorQuestionnaireTitleApi.collectTitle(req);
        }catch (Exception e){

            baseResponse.setCode(ResultCode.ERROR);
            baseResponse.setMessage("收藏问卷题目失败");
        }
        return baseResponse;
    }

    /**
     * @description: 删除收藏的问卷题目
     * @author: chenJij@bsoft.com.cn
     * @date: 2021/10/11 14:56
     * @param: req
     * @return: com.bsoft.gol.editor.editor.BaseResponse
     */
    @RequestMapping("/cancelCollection")
    public BaseResponse cancelCollection(@RequestBody CollectTitleRequest req) {
        BaseResponse baseResponse = new BaseResponse<>();
        try {
            editorQuestionnaireTitleApi.cancelCollection(req);
        }catch (Exception e){

            baseResponse.setCode(ResultCode.ERROR);
            baseResponse.setMessage("删除收藏的问卷题目失败");
        }
        return baseResponse;
    }

    /**
     * @description: 通过题目id获取题目选项列表
     * @author: chenJij@bsoft.com.cn
     * @date: 2021/10/11 14:56
     * @param: req
     * @return: com.bsoft.gol.editor.editor.BaseResponse
     */
    @RequestMapping("/queryEditorTitleOptionList")
    public BaseResponse queryEditorTitleOptionList(@RequestBody CollectTitleRequest req) {
        BaseResponse baseResponse = new BaseResponse<>();
        try {
            List<EditorTitleOption> editorTitleOptions = editorQuestionnaireTitleApi.queryEditorTitleOptionList(req.getTitleId());
            baseResponse.setData(editorTitleOptions);
        }catch (Exception e){
            baseResponse.setCode(ResultCode.ERROR);
            baseResponse.setMessage("通过题目id获取题目选项列表失败");
        }
        return baseResponse;
    }

}